<?php 

class ContentController extends Controller{
	private $db;
	public function __init()
	{
		$this->db= K('Content');
	}
	public function index()
	{
		$data=$this->db->getList();
		$this->assign($data);//////
		$this->display();
	}
	//添加文章
	public function add()
	{
		if (IS_POST) {
			if ($this->db->addContent()) {
				$this->success('添加成功','index');
			}else{
				$this->error('添加失败');
			}
		}else{
			$catdb=K('Category')->getList();
			$this->assign('cat',$catdb);
			$this->display();
		}
	}
	//编辑文章
	public function edit()
	{
		if (IS_POST) {
			if ($this->db->editContent(Q('aid'))) {
				$this->success('编辑成功','index');
			}else{
				$this->error($this->db->error);
			}	
		}else{
			$catdb=K('Category')->getList();
			$this->assign('cat',$catdb);
			//读取文章数据
			$aid=Q('aid',0,'intval');
			//加上field category和content有相同字段，关联后category在前级别高，顶掉了content里相同的字段
			$filed=$this->db->field('*,content.keywords,content.description')->find();
			//缩略图 统一为二维数组形式 方便多张图片上传
			$filed['thumb']=array(
				array('path'=>$filed['thumb'])
				);
			$this->assign('filed',$filed);
			$this->display();
		}
	}
	//删除文章
	public function del($value='')
	{
		$cid=Q('cid',0,'intval');
		if ($this->db->delContent(Q('aid'))) {
			$this->success('删除成功','index');
		}else{
			$this->error($this->db->error);
		}
	}

}

 ?>